package LoginServer;

import Library.Login.*;
import Library.*;
import java.rmi.*;
import java.rmi.server.*;

/**
 * Gateway naar LoginServer, omdat Threads niet Serializable zijn. 
 */
public class Gateway extends UnicastRemoteObject implements ILoginGateway
{
    /**
     *
     */
    protected transient LoginServer m_LoginServer;
    
    /**
     * Constructor voor het aanmaken van een Gateway
     * @throws RemoteException
     */
    public Gateway() throws RemoteException
    {
    }
    
    /**
     * Stelt de loginserver voor de gateway in
     * @param server loginserver
     */
    public void SetLoginServer(LoginServer server)
    {
        m_LoginServer = server;
    }
    
    /**
     * Roept logout aan op de loginserver
     * @param ticket ticket
     * @throws RemoteException
     */
    public void logout(ITicket ticket) throws RemoteException
    {
        try
        {
            m_LoginServer.logout(ticket);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

    /**
     * Roept login aan op de loginserver
     * @param username 
     * @param password wachtwoord
     * @return ticket
     * @throws RemoteException
     */
    public ActionResult<ITicket> login(String username, int password)
        throws RemoteException
    {
        try
        {
            return m_LoginServer.login(username, password);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    /**
     * Roept createAccount aan op de loginserver
     * @param username username
     * @param password wachtwoord
     * @return result (zie Library.ErrorCodes)
     * @throws RemoteException
     */
    public int createAccount(String username, int password)
        throws RemoteException
    {
        try
        {
            int result = m_LoginServer.createAccount(username, password);
            return result;
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        int result = ErrorCodes.ERROR_UNKNOWN;
        return result;
    }


}
